import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-09-02
 * Time: 11:49
 */
public class test_6 {
    public ArrayList<Integer> intersection(ArrayList<Integer> nums1, ArrayList<Integer> nums2) {
        // write code here
        ArrayList<Integer> ret = new ArrayList<>();
        HashMap<Integer, Boolean> hashMap = new HashMap<>();
        for (Integer n : nums2) {
            hashMap.put(n, true);
        }
        for (Integer n : nums1) {
            Boolean b = hashMap.getOrDefault(n, false);
            hashMap.put(n, false);
            if (b) {
                ret.add(n);
            }
        }

        System.out.println(ret);
        return ret;
    }
}
